<template>
  <div class="login-container">
    <UserIndexTop showfun="login" :topnav="nav"></UserIndexTop>
    <el-form class="login-form" ref="validate">
      <div class="round">
        <img src="@/assets/config_images/Oval.png" alt />
      </div>
      <div class="login-img">
        <img src="@/assets/config_images/login-img.png" alt />
      </div>
      <div class="login-con">
        <div class="login-con-top" @click="showcode = !showcode">
          <img src="@/assets/config_images/erweima.png" alt />
        </div>
        <div class="login-main">
          <el-tabs v-model="activeName" v-if="!showcode">
            <el-tab-pane label="密码登录" name="first">
              <el-form-item prop="username">
                <span class="svg-container">
                  <svg-icon icon-class="user" />
                </span>
                <el-input
                  ref="username"
                  v-model="loginForm.mobile"
                  placeholder="用户名"
                  name="user"
                  type="text"
                  tabindex="1"
                  auto-complete="on"
                />
              </el-form-item>
              <el-form-item prop="password">
                <span class="svg-container">
                  <svg-icon icon-class="password" />
                </span>
                <el-input
                  ref="password"
                  v-model="loginForm.password"
                  type="password"
                  placeholder="密码"
                  name="password"
                  tabindex="2"
                  auto-complete="on"
                  @keyup.enter.native="handleLogin"
                />
              </el-form-item>
              <div class="login-bot">
                <el-checkbox label="两周内自动登录" name="type"></el-checkbox>
                <router-link to="#" style="color:#616161;font-size:14px;">忘记密码？</router-link>
              </div>
            </el-tab-pane>
            <!-- <el-tab-pane label="验证码登录" name="second">
              <el-form-item prop="phone">
                <span class="svg-container">
                  <svg-icon icon-class="user" />
                </span>
                <el-input
                  ref="username"
                  v-model="loginForm.phone"
                  placeholder="手机号"
                  name="phone"
                  type="text"
                  tabindex="1"
                  auto-complete="on"
                />
              </el-form-item>
              <div class="get-code">
                <el-form-item prop="code" class="my-code">
                  <div style="display:flex">
                    <span class="svg-container">
                      <svg-icon icon-class="user" />
                    </span>
                    <el-input
                      ref="code"
                      v-model="loginForm.code"
                      placeholder="验证码"
                      name="code"
                      type="text"
                      tabindex="1"
                      auto-complete="on"
                    />
                  </div>
                </el-form-item>
                <p v-if="num==0" class="code-btn" @click="timer()">{{verification}}</p>
                <p
                  v-else-if="num<=60"
                  class="code-btn disa_bled"
                  @click="timer()"
                  disabled="disabled"
                >{{verification}}</p>
              </div>
            </el-tab-pane> -->
            <div class="login-btn" v-on:click="handleLogin">
              <span>登录</span>
            </div>
          </el-tabs>
          <div class="er-code" v-if="showcode">
            <img src="@/assets/config_images/erweima.png" alt />
            <div class="er-code-bot">
              <svg-icon icon-class="saoyisao" />
              <span>打开微信，扫一扫登陆</span>
            </div>
          </div>
        </div>
        <div class="other-login">
          <span>
            其他账号登录
            <svg-icon icon-class="qq" style="color:#8CE6F9;" />
            <svg-icon icon-class="微信" />
          </span>
          <!-- <router-link to="/register" style="color:#1F75F6">
            <span>立即注册</span>
          </router-link> -->
        </div>
      </div>
    </el-form>
    <UserIndexBot></UserIndexBot>
  </div>
</template>

<script>
import UserIndexTop from "@/components/IndexCon/userindextop";
import UserIndexBot from "@/components/IndexCon/userindexbot";
export default {
  name: "Login",
  components: {
    UserIndexTop,
    UserIndexBot
  },
  data() {
    return {
      num: 0,
      verification: "验证码",
      activeName: "first",
      showcode: false,
      nav: [
        {
          text: "注册",
          link: "/register"
        },
        {
          text: "招商加盟",
          link: "/manage/order"
        }
      ],
      loginForm: {
        mobile: "",
        password: "",
        phone: "",
        code: ""
      },
      loading: false
    };
  },
  methods: {
    handleLogin() {
      this.loading = true;
      this.$store
        .dispatch("user/userLogin", this.loginForm)
        .then(() => {
          this.$router.push({ path: "/manage" });
          this.loading = false;
        })
        .catch(() => {
          this.loading = false;
        });
    },
    timer() {
      var _this = this;
      this.num = 60;
      var timer = setInterval(function() {
        // console.log(_this.num);
        _this.num--;
        _this.verification = "已发送" + "(" + _this.num + ")";
        if (_this.num === 0) {
          _this.verification = "验证码";
          clearInterval(timer);
        }
      }, 1000);
    }
  }
};
</script>

<style lang="scss">
/* 修复input 背景不协调 和光标变色 */
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */

$bg: #e5e5e5;
$light_gray: #353535;
$cursor: #000;

@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  .login-container .el-input input {
    color: $cursor;
  }
}

/* reset element-ui css */
.login-container {
  .login-bot {
    display: flex;
  }
  .login-btn {
    width: 280px;
    height: 44px;
    background: rgba(31, 117, 246, 1);
    border-radius: 2px;
    color: #fff;
    text-align: center;
    line-height: 44px;
    margin-top: 18px;
    cursor: pointer;
  }
  .other-login {
    width: 100%;
    height: 60px;
    display: flex;
    color: #616161;
    font-size: 14px;
    align-items: center;
    padding: 0 5px;
    position: absolute;
    bottom: 0;
    left: 0;
    background: rgba(244, 249, 255, 1);
    border-radius: 0px 0px 2px 2px;
    justify-content: space-between;
    svg {
      font-size: 16px;
      color: #8ce6f9;
      margin-left: 10px;
      cursor: pointer;
    }
  }
  .el-input {
    display: inline-block;
    height: 47px;
    width: 85%;

    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;
      color: $light_gray;
      height: 44px;
      caret-color: $cursor;
      &:-webkit-autofill {
        box-shadow: 0 0 0px 1000px $bg inset !important;
        -webkit-text-fill-color: $cursor !important;
      }
    }
  }

  .el-form-item {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.1);
    border-radius: 5px;
    color: #454545;
  }
}
</style>
<style lang="scss" scoped>
$bg: linear-gradient(
  270deg,
  rgba(140, 230, 249, 1) 0%,
  rgba(106, 162, 233, 1) 100%
);
$dark_gray: #889aa4;
$light_gray: #eee;

.login-container {
  width: 100%;
  min-height: 100%;
  min-width: 1024px;
  background: $bg;
  overflow: hidden;

  .login-form {
    position: relative;
    width: 100%;
    max-width: 100%;
    display: flex;
    margin: 0 auto;
    overflow: hidden;
    .round {
      position: relative;
      width: 10%;
      margin-top: 310px;
      float: left;
      img {
        max-width: 100%;
        height: auto;
      }
    }
    .login-img {
      position: relative;
      width: 40%;
      padding-top: 214px;
      padding-left: 120px;
      float: left;
      img {
        max-width: 100%;
        height: auto;
      }
    }
    .login-con {
      position: absolute;
      width: 18%;
      height: 430px;
      left: 66%;
      top: 36%;
      background: rgba(255, 255, 255, 1);
      box-shadow: 0px 0px 6px 0px rgba(0, 0, 0, 0.2);
      border-radius: 3px;
      .login-con-top {
        width: 100%;
        height: 56px;
        img {
          float: right;
        }
      }
      .login-main {
        padding: 4px 30px;
        .er-code {
          width: 220px;
          height: 220px;
          border: 1px solid rgba(223, 223, 223, 1);
          margin: 0 auto;
          padding: 27px 30px 0;
          img {
            width: 150px;
          }
          .er-code-bot {
            font-size: 14px;
            font-weight: 400;
            color: rgba(115, 130, 153, 1);
            line-height: 21px;
            margin-top: 10px;
          }
        }
      }
    }
  }
  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }
  .get-code {
    width: 100%;
    height: 54px;
    display: flex;
    align-items: center;
    margin-top: 33px;
    .my-code {
      width: 180px;
      height: 54px;
    }
    .code-btn {
      width: 78px;
      color: #fff;
      margin-left: 20px;
      height: 48px;
      background: rgba(31, 117, 246, 1);
      border-radius: 2px;
      line-height: 48px;
      text-align: center;
      margin-top: -10px;
      cursor: pointer;
    }
    .disa_bled {
      pointer-events: none;
      opacity: 0.6;
    }
  }
  .svg-container {
    padding: 6px 5px 6px 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }

  .title-container {
    position: relative;

    .title {
      font-size: 26px;
      color: $light_gray;
      margin: 0px auto 40px auto;
      text-align: center;
      font-weight: bold;
    }
  }

  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
}
</style>
